package util;

import java.util.List;

public class Transform {
    //数组转置（String类型）
    public static String[][] transpose(String[][] array)
    {
        int columnLength = array[0].length;
        int rowLength = array.length;
        String[][] trans_array = new String[columnLength][rowLength] ;

        //转置
        for(int i=0; i<columnLength;i++)
        {
            for(int j=0;j<rowLength;j++ )
            {
                trans_array[i][j] = array[j][i];

            }
        }
        return  trans_array;
    }

    //int数组转为String数组
    public static String[] toStringArray(int[] array) {
        int length = array.length;
        String[] trans_array = new String[length];

        //转置
        for (int i = 0; i < length; i++) {
            trans_array[i] = String.valueOf(array[i]);
        }
        return trans_array;
    }

    //double数组转为String数组
    public static String[] toStringArray(double[] array) {
        int length = array.length;
        String[] trans_array = new String[length];

        //转置
        for (int i = 0; i < length; i++) {
            trans_array[i] = String.valueOf(array[i]);
        }
        return trans_array;
    }

    //String数组转为double数组
    public static double[] toDoubleArray(String[] array) {
        int length = array.length;
        double[] trans_array = new double[length];

        //转置
        for (int i = 0; i < length; i++) {
            trans_array[i] = Double.valueOf(array[i]);
        }
        return trans_array;
    }


    //String数组转为int数组
    public static int[] toIntArray(String[] array) {
        int length = array.length;
        int[] trans_array = new int[length];

        //转置
        for (int i = 0; i < length; i++) {
            trans_array[i] = Integer.valueOf(array[i]);
        }
        return trans_array;
    }

    //List转为int类型数组
    public static void ListToArray(List list,int[] array) {
        int size=list.size();
        for(int i=0;i<size;i++){
            array[i]=(int)list.get(i);
        }
    }

    //List转为int类型数组
    public static void ListToArray(List list,double[] array) {
        int size=list.size();
        for(int i=0;i<size;i++){
            array[i]=(double)list.get(i);
        }
    }
}
